// 保存
const saveToStorage = function (key, val) {
  let music = localStorage.getItem('__music__')
  if (!music) {
    music = {}
  } else {
    music = JSON.parse(music)
  }
  music[key] = val
  localStorage.setItem('__music__', JSON.stringify(music))
}

// 读取
const loadFromStorage = function (key, def) {
  let music = localStorage.getItem('__music__')
  if (!music) {
    // 如果不存在，返回默认值
    return def
  }
  music = JSON.parse(music)
  // 如果不存在，返回默认值
  const ret = music[key] || def
  return ret
}

export { saveToStorage, loadFromStorage }
